from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-23 14:02:40.380722
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 23, May, 2022
Time: 14:02:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3879
Nobs: 665.000 HQIC: -49.7609
Log likelihood: 8221.62 FPE: 1.93479e-22
AIC: -49.9969 Det(Omega_mle): 1.69159e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.310522 0.060103 5.167 0.000
L1.Burgenland 0.106923 0.038709 2.762 0.006
L1.Kärnten -0.109806 0.020334 -5.400 0.000
L1.Niederösterreich 0.201216 0.080598 2.497 0.013
L1.Oberösterreich 0.124146 0.079777 1.556 0.120
L1.Salzburg 0.256621 0.041178 6.232 0.000
L1.Steiermark 0.043329 0.053995 0.802 0.422
L1.Tirol 0.103069 0.043518 2.368 0.018
L1.Vorarlberg -0.063456 0.038568 -1.645 0.100
L1.Wien 0.032410 0.070589 0.459 0.646
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044475 0.127952 0.348 0.728
L1.Burgenland -0.031205 0.082407 -0.379 0.705
L1.Kärnten 0.040459 0.043290 0.935 0.350
L1.Niederösterreich -0.182319 0.171585 -1.063 0.288
L1.Oberösterreich 0.448761 0.169836 2.642 0.008
L1.Salzburg 0.284654 0.087664 3.247 0.001
L1.Steiermark 0.107105 0.114949 0.932 0.351
L1.Tirol 0.312384 0.092644 3.372 0.001
L1.Vorarlberg 0.021761 0.082108 0.265 0.791
L1.Wien -0.038202 0.150275 -0.254 0.799
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184147 0.030854 5.968 0.000
L1.Burgenland 0.089989 0.019872 4.529 0.000
L1.Kärnten -0.007755 0.010439 -0.743 0.458
L1.Niederösterreich 0.257868 0.041376 6.232 0.000
L1.Oberösterreich 0.156017 0.040954 3.810 0.000
L1.Salzburg 0.042396 0.021139 2.006 0.045
L1.Steiermark 0.023497 0.027719 0.848 0.397
L1.Tirol 0.084801 0.022340 3.796 0.000
L1.Vorarlberg 0.052757 0.019799 2.665 0.008
L1.Wien 0.117311 0.036237 3.237 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109949 0.030894 3.559 0.000
L1.Burgenland 0.045753 0.019897 2.299 0.021
L1.Kärnten -0.014169 0.010452 -1.356 0.175
L1.Niederösterreich 0.185136 0.041429 4.469 0.000
L1.Oberösterreich 0.327524 0.041006 7.987 0.000
L1.Salzburg 0.101818 0.021166 4.810 0.000
L1.Steiermark 0.109006 0.027754 3.928 0.000
L1.Tirol 0.096763 0.022369 4.326 0.000
L1.Vorarlberg 0.059283 0.019825 2.990 0.003
L1.Wien -0.022020 0.036284 -0.607 0.544
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115372 0.057501 2.006 0.045
L1.Burgenland -0.044497 0.037033 -1.202 0.230
L1.Kärnten -0.046267 0.019454 -2.378 0.017
L1.Niederösterreich 0.140889 0.077110 1.827 0.068
L1.Oberösterreich 0.162635 0.076324 2.131 0.033
L1.Salzburg 0.281597 0.039396 7.148 0.000
L1.Steiermark 0.055085 0.051658 1.066 0.286
L1.Tirol 0.164500 0.041634 3.951 0.000
L1.Vorarlberg 0.095120 0.036899 2.578 0.010
L1.Wien 0.077801 0.067533 1.152 0.249
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061085 0.045354 1.347 0.178
L1.Burgenland 0.031264 0.029210 1.070 0.284
L1.Kärnten 0.051182 0.015344 3.336 0.001
L1.Niederösterreich 0.208218 0.060820 3.424 0.001
L1.Oberösterreich 0.317502 0.060200 5.274 0.000
L1.Salzburg 0.041533 0.031073 1.337 0.181
L1.Steiermark 0.006779 0.040745 0.166 0.868
L1.Tirol 0.132426 0.032839 4.033 0.000
L1.Vorarlberg 0.064958 0.029104 2.232 0.026
L1.Wien 0.085874 0.053266 1.612 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167181 0.054463 3.070 0.002
L1.Burgenland 0.006542 0.035077 0.187 0.852
L1.Kärnten -0.065115 0.018426 -3.534 0.000
L1.Niederösterreich -0.093962 0.073035 -1.287 0.198
L1.Oberösterreich 0.205790 0.072291 2.847 0.004
L1.Salzburg 0.053504 0.037314 1.434 0.152
L1.Steiermark 0.240904 0.048928 4.924 0.000
L1.Tirol 0.500667 0.039434 12.696 0.000
L1.Vorarlberg 0.058228 0.034949 1.666 0.096
L1.Wien -0.071521 0.063965 -1.118 0.264
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149075 0.060359 2.470 0.014
L1.Burgenland 0.003270 0.038874 0.084 0.933
L1.Kärnten 0.060053 0.020421 2.941 0.003
L1.Niederösterreich 0.180768 0.080943 2.233 0.026
L1.Oberösterreich -0.054849 0.080118 -0.685 0.494
L1.Salzburg 0.206540 0.041354 4.994 0.000
L1.Steiermark 0.134247 0.054225 2.476 0.013
L1.Tirol 0.070169 0.043704 1.606 0.108
L1.Vorarlberg 0.142786 0.038733 3.686 0.000
L1.Wien 0.109717 0.070890 1.548 0.122
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374471 0.035601 10.518 0.000
L1.Burgenland -0.000634 0.022929 -0.028 0.978
L1.Kärnten -0.021817 0.012045 -1.811 0.070
L1.Niederösterreich 0.216802 0.047742 4.541 0.000
L1.Oberösterreich 0.228151 0.047256 4.828 0.000
L1.Salzburg 0.039193 0.024392 1.607 0.108
L1.Steiermark -0.016114 0.031984 -0.504 0.614
L1.Tirol 0.094135 0.025778 3.652 0.000
L1.Vorarlberg 0.053511 0.022846 2.342 0.019
L1.Wien 0.034097 0.041813 0.815 0.415
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037504 0.119914 0.174631 0.143722 0.100923 0.087975 0.041217 0.212018
Kärnten 0.037504 1.000000 -0.018612 0.135102 0.052595 0.090336 0.440467 -0.060112 0.093931
Niederösterreich 0.119914 -0.018612 1.000000 0.324385 0.131109 0.284006 0.078052 0.163410 0.301027
Oberösterreich 0.174631 0.135102 0.324385 1.000000 0.220676 0.309197 0.168268 0.151828 0.252077
Salzburg 0.143722 0.052595 0.131109 0.220676 1.000000 0.129614 0.099921 0.115323 0.130964
Steiermark 0.100923 0.090336 0.284006 0.309197 0.129614 1.000000 0.138867 0.119682 0.051392
Tirol 0.087975 0.440467 0.078052 0.168268 0.099921 0.138867 1.000000 0.069992 0.148094
Vorarlberg 0.041217 -0.060112 0.163410 0.151828 0.115323 0.119682 0.069992 1.000000 0.008580
Wien 0.212018 0.093931 0.301027 0.252077 0.130964 0.051392 0.148094 0.008580 1.000000